<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
	xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <!-- TopJUI框架样式 -->
    <link type="text/css" href="/topjui/themes/default/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="/topjui/themes/default/topjui.blue.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="/static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- layui框架样式 -->
    <link type="text/css" href="/static/plugins/layui/css/layui.css" rel="stylesheet"/>
    <!-- iconfont字体图标 -->
	<link type="text/css" href="/static/plugins/iconfont/iconfont.css" rel="stylesheet"/>
    
    <!-- jQuery相关引用 -->
    <script type="text/javascript" src="/static/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/static/plugins/jquery/jquery.cookie.js"></script>
    <!-- TopJUI框架配置 -->
    <script type="text/javascript" src="/static/public/js/topjui.config.js"></script>
    <!-- TopJUI框架核心-->
    <script type="text/javascript" src="/topjui/js/topjui.core.min.js"></script>
    <!-- TopJUI中文支持 -->
    <script type="text/javascript" src="/topjui/js/locale/topjui.lang.zh_CN.js"></script>
    <!-- layui框架js -->
    <script type="text/javascript" src="/static/plugins/layui/layui.js" charset="utf-8"></script>
	
	<script type="text/javascript">
		function generatorCode() {
			var dbNames = [];
			var tableNames = [];
			var rows = $('#table-list').iDatagrid('getChecked');
			if(rows != null && rows.length > 0) {
				for (var i = 0; i < rows.length; i++) {
					var row = rows[i];
					dbNames.push(row.dbName);
					tableNames.push(row.tableName);
				}
				location.href = "/system/db/generatorCode?dbNames=" + encodeURI(JSON.stringify(dbNames)) + "&tableNames=" + encodeURI(JSON.stringify(tableNames));
			} else {
				$.iMessager.alert("操作提示", "请先选择要操作的数据", 'messager-info');
			}
		}
	</script>
</head>

<body>
	<div sec:authorize="hasAuthority('system:db')" data-toggle="topjui-layout" data-options="fit:true">
		<!-- 数据库列表 -->
	    <div sec:authorize="hasAuthority('system:db:list')" data-options="region:'west',width:'20%',title:'',split:true,border:false,bodyCls:'border_right'">
	        <table data-toggle="topjui-datagrid" data-options="
				id:'db-list',url:'/system/db/list',
				fitColumns:true,singleSelect:true,selectOnCheck:false,checkOnSelect:false,pagination:false,
				childGrid:{
					grid:[{type:'datagrid',id:'table-list'}],
					param:'dbName:dbName'
				}">
				<thead>
					<tr>
						<th data-options="field:'dbName',title:'数据库',width:100"></th>
					</tr>
				</thead>
			</table>
	    </div>
		
		<!-- 数据表列表 -->
		<div sec:authorize="hasAuthority('system:db:table:list')" data-options="region:'center',title:'',split:true,border:false,bodyCls:'border_left_right'">
			<table data-toggle="topjui-datagrid" data-options="
				id:'table-list',url:'/system/db/table/list',
				fitColumns:true,singleSelect:true,selectOnCheck:false,checkOnSelect:false,pageSize:50,
				childGrid:{
					grid:[{type:'datagrid',id:'column-list'}],
					param:'dbName:dbName,tableName:tableName'
				}">
				<thead>
					<tr>
						<th data-options="field:'id',title:'ID',checkbox:true"></th>
						<th data-options="field:'dbName',title:'数据库',hidden:true"></th>
						<th data-options="field:'tableName',title:'数据表',width:100"></th>
						<th data-options="field:'tableComment',title:'注释',width:100"></th>
					</tr>
				</thead>
			</table>
		</div>
		
		<!-- 数据字段列表 -->
 		<div sec:authorize="hasAuthority('system:db:column:list')" data-options="region:'east',width:'50%',title:'',split:true,border:false,bodyCls:'border_left'">
			<table data-toggle="topjui-datagrid" data-options="
				id:'column-list',url:'/system/db/column/list',
				fitColumns:true,singleSelect:true,selectOnCheck:false,checkOnSelect:false,pageSize:50">
				<thead>
					<tr>
						<th data-options="field:'id',title:'ID',checkbox:true"></th>
						<th data-options="field:'dbName',title:'数据库',hidden:true"></th>
						<th data-options="field:'tableName',title:'数据表',width:100,hidden:true"></th>
						<th data-options="field:'columnName',title:'数据字段',width:100"></th>
						<th data-options="field:'columnType',title:'字段类型',width:100"></th>
						<th data-options="field:'isNull',title:'是否为空',width:60"></th>
						<th data-options="field:'columnKey',title:'索引类型',width:60"></th>
						<th data-options="field:'columnComment',title:'注释',width:100"></th>
						<th data-options="field:'extra',title:'其他信息',width:60,hidden:true"></th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	
	<!-- 数据表表格工具栏 -->
	<div sec:authorize="hasAuthority('system:db:table:list')" id="table-list-toolbar" class="topjui-toolbar" data-options="grid:{type:'datagrid', id:'table-list'}">
		<a sec:authorize="hasAuthority('system:db:code')" href="javascript:void(0)" data-toggle="topjui-menubutton" data-options="
			onClick: generatorCode,
			method:'doAjax',
			extend: '#generator-list-toolbar',
			iconCls:'fa fa-code',
			confirmMsg:'确认生成代码？',
			grid: {uncheckedMsg:'请先勾选数据',param:'dbNames:dbName,tableNames:tableName'}">生成代码</a>
			
		<a sec:authorize="hasAuthority('system:db:table:add')" href="javascript:void(0)" data-toggle="topjui-menubutton" data-options="
			method:'openDialog',
			extend:'#table-list-toolbar',
			iconCls:'fa fa-plus',
			parentGrid:{
				type:'datagrid',
				id:'db-list',
				param:'dbName:dbName',
				unselectedMsg:'请先选中数据库'
			},
			dialog:{
  				id:'table-add-dialog',
				title:'新增信息',
				href:'/system/db/table/add_view',
				width:'60%',
				height:'60%',
				buttonsGroup:[{
					text:'确定',
					url:'/system/db/table/add',
					iconCls:'fa fa-plus',
					handler:'ajaxForm',
					btnCls:'topjui-btn-green'
				}]
			}">新增</a>
			
		<a sec:authorize="hasAuthority('system:db:table:edit')" href="javascript:void(0)" data-toggle="topjui-menubutton" data-options="
			method:'openDialog',
			extend:'#table-list-toolbar',
			iconCls:'fa fa-pencil',
			dialog:{
				id:'table-update-dialog',
				title:'编辑信息',
				href: '/system/db/table/edit_view?dbName={dbName}&tableName={tableName}',
				width:'60%',
				height:'60%',
				buttonsGroup:[{
					text:'确定',
					url:'/system/db/table/edit',
					iconCls:'fa fa-plus',
					handler:'ajaxForm',
					btnCls:'topjui-btn-green'
				}]
			}">编辑</a>
			
		<a sec:authorize="hasAuthority('system:db:table:delete')" href="javascript:void(0)" data-toggle="topjui-menubutton" data-options="
			method:'doAjax',
			extend:'#table-list-toolbar',
			iconCls:'fa fa-trash',
			confirmMsg:'确认删除已选择的数据？',
			grid: {uncheckedMsg:'请先勾选要删除的数据',param:'dbNames:dbName,tableNames:tableName'},
			url:'/system/db/table/delete'">删除</a>
	</div>
	
	<!-- 数据字段表格工具栏 -->
	<div sec:authorize="hasAuthority('system:db:column:list')" id="column-list-toolbar" class="topjui-toolbar" data-options="grid:{type:'datagrid', id:'column-list'}">
		<a sec:authorize="hasAuthority('system:db:column:add')" href="javascript:void(0)" data-toggle="topjui-menubutton" data-options="
			method:'openDialog',
			extend:'#column-list-toolbar',
			iconCls:'fa fa-plus',
			parentGrid:{
				type:'datagrid',
				id:'table-list',
				param:'dbName:dbName,tableName:tableName',
				unselectedMsg:'请先选中的数据表'
			},
			dialog:{
  				id:'column-add-dialog',
				title:'新增字段信息',
				href:'/system/db/column/add_view',
				width:'60%',
				height:'60%',
				buttonsGroup:[{
					text:'确定',
					url:'/system/db/column/add',
					iconCls:'fa fa-plus',
					handler:'ajaxForm',
					btnCls:'topjui-btn-green'
				}]
			}">新增</a>
			
		<a sec:authorize="hasAuthority('system:db:column:edit')" href="javascript:void(0)" data-toggle="topjui-menubutton" data-options="
			method:'openDialog',
			extend:'#column-list-toolbar',
			iconCls:'fa fa-pencil',
			dialog:{
				id:'column-update-dialog',
				title:'编辑字段信息',
				href: '/system/db/column/edit_view?dbName={dbName}&tableName={tableName}&columnName={columnName}',
				width:'60%',
				height:'60%',
				buttonsGroup:[{
					text:'确定',
					url:'/system/db/column/edit',
					iconCls:'fa fa-plus',
					handler:'ajaxForm',
					btnCls:'topjui-btn-green'
				}]
			}">编辑</a>
			
		<a sec:authorize="hasAuthority('system:db:column:delete')" href="javascript:void(0)" data-toggle="topjui-menubutton" data-options="
			method:'doAjax',
			extend:'#column-list-toolbar',
			iconCls:'fa fa-trash',
			confirmMsg:'确认删除已选择的数据？',
			grid: {uncheckedMsg:'请先勾选要删除的数据',param:'dbNames:dbName,tableNames:tableName,columnNames:columnName'},
			url:'/system/db/column/delete'">删除</a>
	</div>
</body>
</html>